<%--                                                                       --%>
<%-- Copyright (c) 2004-2005 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>

<%
  String ctxPath = request.getContextPath();
%>

<%@ include file="/mt/common/pickerPopupHelper.jsp" %>

<script language="JavaScript">

function doEntityMovePopup(programId) {
  document.PortletEntityManager.programId.value = programId;
  doPickerPopupAction('<c:url value="/mt/categoryPickerPopup.do"/>','moveEntity',317,
    null,null,null,true,true,false,null,null,0,false);
}

function doEntitiesMovePopup() {
  doPickerPopupAction('<c:url value="/mt/categoryPickerPopup.do"/>','moveEntities',317,
    null,null,null,true,true,false,null,null,0,false);
}

function moveEntity(ids,names) {
  if(ids.length>=1 && names.length>=1) {
    var action = '<c:url value="/ep/portletEntityUncategorizedMove.do"/>';
    if (action.indexOf("?") == -1) {
      action += "?";
    }
    action += "programId=" + document.PortletEntityManager.programId.value;
    action += "&parentCatId=" + ids[0];
    
    document.PortletEntityManager.action = action;
    document.PortletEntityManager.submit();
  }
}

function moveEntities(ids,names) {
  if(ids.length>=1 && names.length>=1) {
    var action = '<c:url value="/ep/portletEntityUncategorizedMove.do"/>';
    if (action.indexOf("?") == -1) {
      action += "?";
    }
    action += "parentCatId=" + ids[0];
    
    document.portletEntityListForm.action = action;
    document.portletEntityListForm.submit();
  }
}

function doPortletEditEntity(programId) {
  var action = '<c:url value="/ep/portletEntityEdit.do"/>';
  if (action.indexOf("?") == -1) {
    action += "?";
  }
  action += "programId=" + programId;
  
  document.PortletEntityManager.action = action;
  document.PortletEntityManager.submit();
}

function doPortletDeleteEntity(programId) {
  if (confirm('<bean:message key="ep.portlet.alert.confirmDeletePortletEntity" bundle="ep.messages"/>')) {
    var action = '<c:url value="/ep/portletEntityUncategorizedDelete.do"/>';
    if (action.indexOf("?") == -1) {
      action += "?";
    }
    action += "programId=" + programId;
    
    document.PortletEntityManager.action = action;
    document.PortletEntityManager.submit();
  }
}

function doPortletEntitySetStatus(status, portletEntityId) {
  var action = '<c:url value="/ep/portletEntityUncategorizedBrowseSetStatus.do"/>';
  if (action.indexOf("?") == -1) {
    action += "?";
  }
  action += "programId=" + portletEntityId;
  action += "&status=" + status;
  
  document.PortletEntityManager.action = action;
  document.PortletEntityManager.submit();
}

<%@ include file="/mc/common/jsutils.jsp" %>

</script>

<c:set var="deleteImg">
<img src="<%= ctxPath %>/ep/images/action/icon_delete.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean:message key="image.alt.delete" bundle="ep.messages"/>" title="<bean:message key="image.alt.delete" bundle="ep.messages"/>">
</c:set>
<c:set var="moveImg">
<img src="<%= ctxPath %>/ep/images/action/icon_move.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean:message key="image.alt.move" bundle="ep.messages"/>" title="<bean:message key="image.alt.move" bundle="ep.messages"/>">
</c:set>
<c:set var="editImg">
<img src="<%= ctxPath %>/ep/images/action/icon_edit.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean:message key="image.alt.edit" bundle="ep.messages"/>" title="<bean:message key="image.alt.edit" bundle="ep.messages"/>">
</c:set>
<c:set var="offlineImg">
<img src="<%= ctxPath %>/ep/images/action/icon_offline.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean:message key="image.alt.setOffline" bundle="ep.messages"/>" title="<bean:message key="image.alt.setOffline" bundle="ep.messages"/>">
</c:set>
<c:set var="onlineImg">
<img src="<%= ctxPath %>/ep/images/action/icon_online.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean:message key="image.alt.setOnline" bundle="ep.messages"/>" title="<bean:message key="image.alt.setOnline" bundle="ep.messages"/>">
</c:set>

<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="content area">
  <tr>
    <td valign="top" width="100%">
      <div class="pageTitle">
      <bean:message key="ep.portlet.entities.manage.page.title" bundle="ep.messages"/>
      </div>
      <div class="errorMessage"><html:errors bundle="ep.messages"/></div>
      <div>
      <%@include file="/mc/common/pagetab.jsp" %>
      </div>

      <div class="pageSubtitle">
        <span class="left"><bean:message key="ep.portlet.entities" bundle="ep.messages"/></span>

        <span class="right">
        </span>
      </div>

<form name="portletEntityListForm" action="/ep/portletEntityView.do" method="post">
<input type="hidden" name="ctx.f" value="<c:out value="${requestScope['ctx.f']}"/>"/>

<logic:notEmpty name="list">
      <div class="globalButtonWrap">
        <input type="button" name="selectAllPortletEntities" class="globalButton" 
          onclick="check(this.form.programIds, this);" value="<bean:message key="button.selectAll" bundle="ep.messages"/>">
        <input type="button" class="globalButton" value="<bean:message key="button.move" bundle="ep.messages"/>" 
          onclick="if (isAnyChecked(this.form.programIds, '<bean:message key="ep.portlet.alert.atLeastOnePortletEntity" bundle="ep.messages"/>', '')) doEntitiesMovePopup();">
        <input type="button" name="deletePortletEntities" class="globalButton" 
          onclick="if (isAnyChecked(this.form.programIds, '<bean:message key="ep.portlet.alert.atLeastOnePortletEntity" bundle="ep.messages"/>', '<bean:message key="ep.portlet.alert.confirmDeletePortletEntity" bundle="ep.messages"/>')) doAction('/ep/portletEntityDelete.do', this.form);"
          value='<bean:message key="button.delete" bundle="ep.messages"/>'>
      </div>
</logic:notEmpty>

      <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="Search result table" width="100%">
        <tr class="listHeader">
          <th id="Checkboxes">&nbsp;</th>
          <th id="Name" align="left"><bean:message key="ep.header.name.portlet.entity" bundle="ep.messages"/></th>
          <th id="Producer" align="left"><bean:message key="ep.header.name.producer" bundle="ep.messages"/></th>
          <th id="LastModifiedDate" align="left"><bean:message key="ep.header.lastModifiedDate" bundle="ep.messages"/></th>
          <th id="Actions" align="left" nowrap><bean:message key="ep.header.actions" bundle="ep.messages"/></th>
        </tr>

        <!-- results -->

<logic:iterate id="item" name="list" indexId="index">
        <tr class="<%= index.intValue() % 2 == 0 ? "listEven" : "listOdd" %>">
          <td headers="Checkboxes" align="center"><input type="checkbox" name="programIds" value="<c:out value="${item.map.id}"/>"></td>
          <td headers="Name"><html:link page="/ep/portletEntityView.do"
            paramId="programId" paramName="item" paramProperty="id"><bean:write
            name="item" property="name"/></html:link></td>
          <td headers="Producer"><bean:write name="item" property="producerName"/></td>
          <td headers="LastModifiedDate">
            <bean:write name="item" property="lastModifiedDate" bundle="ep.messages"
                   formatKey="format.datetime.long"/>
          </td>
          <td headers="Actions">
            <a href="#" onclick="doPortletEditEntity('<c:out value="${item.map.id}"/>');"><c:out
            value='${editImg}' escapeXml="false"/></a>
            <a href="#" onclick="doEntityMovePopup('<c:out value="${item.map.id}"/>');"><c:out
            value='${moveImg}' escapeXml="false"/></a>
            <c:choose>
              <c:when test="${item.map.status == 0}">
              <a href="#" onclick="doPortletEntitySetStatus(1, '<c:out value="${item.map.id}"/>');"><c:out
              value='${onlineImg}' escapeXml="false"/></a>
              </c:when>
              <c:otherwise>
              <a href="#" onclick="doPortletEntitySetStatus(0, '<c:out value="${item.map.id}"/>');"><c:out
              value='${offlineImg}' escapeXml="false"/></a>
              </c:otherwise>
            </c:choose>
            <a href="#" onclick="doPortletDeleteEntity('<c:out value="${item.map.id}"/>');"><c:out
            value='${deleteImg}' escapeXml="false"/></a>
          </td>
        </tr>
</logic:iterate>

      </table>
</form>
      <!-- pagination -->
<%@ include file="/mc/common/pager.jsp" %>

    </td>
  </tr>
</table>
<form name="PortletEntityManager" method="post">
<input type="hidden" name="categoryId" value=""/>
<input type="hidden" name="programId" value=""/>
</form>
